import { Component, Injector, ViewChild, ElementRef, Renderer, } from '@angular/core';
import { Tabs, App,IonicApp } from 'ionic-angular';
import { BasePage } from '../basePage';
import { TweenMax, TweenLite } from "gsap";
import { Events } from 'ionic-angular';
import { StorageService } from './../../providers/StorageService';
// import { BackButtonService } from "../../providers/backButtonService";
import { BackButtonProvider } from "../../providers/back-button/back-button";
// import { BackButtonService } from '../../providers/backButton'

// import { Platform } from 'ionic-angular';
@Component({
  selector: 'page-tabs',
  templateUrl: 'tabs.html'
})
export class TabsPage extends BasePage {

  mySelectedIndex = 0;
  tab1Root = "home";    //美图
  tab2Root = "about";   //美甲师
  tab3Root = "shopSearch";//美甲店
  tab4Root = "contact"; //周边
  tab5Root = "personal";//我的
  //中间圆球旋转
  currRotion = 0;
  @ViewChild('myTabs') tabRef: Tabs;
  @ViewChild('fabBtn') fabBtn: any;
  

  //name:any=this.navParams.get("name");

  constructor(injector: Injector,
    public events: Events,
    public backButtonService: BackButtonProvider,
    private elementRef: ElementRef,
    private renderer: Renderer,
    public ionicApp:IonicApp,
    public app: App,
    // private platform: Platform,
    public stc: StorageService, ) {
    super(injector);
    this.platform.ready().then(() => {
      this.backButtonService.registerBackButtonAction(this.tabRef,null,this.ionicApp);
    });

  }

  ionViewDidLoad() {
    /*预加载一些图片*/
    this.preload();
   

  }
  
    // history.go(0)
    // return false

  ionViewWillUnload() {
    // let selectIndex=this.stc.read('selectIndex')?this.stc.read('selectIndex'):0;
    // console.log(selectIndex);
  }

  flag = true;
  registerBackButton  
  exitApp () {  
      if (this.registerBackButton) {  
          this.platform.exitApp()  
      } else {  
          this.registerBackButton = true  
          this.toastCtrl.create({  
              message: '再按一次退出应用',  
              duration: 2000,  
              position: 'top',  
              cssClass: 'toast-black'  
          }).present();  
          setTimeout(() => this.registerBackButton = false, 2000);//2秒内没有再次点击返回则将触发标志标记为false  
      }  
  } 
  openMore = () => {
    let element = this.fabBtn.nativeElement;
    this.currRotion += 45;
    this.flag = !this.flag;

    TweenLite.to(element, 0.5, { rotation: this.currRotion });

  }
  preload(){
    var images = new Array()
    let preloads = ['http://localhost:8100/assets/img/1-2.png',
                    'http://localhost:8100/assets/img/2-2.png',
                    'http://localhost:8100/assets/img/3-2.png',
                    'http://localhost:8100/assets/img/4-2.png',
                    'http://localhost:8100/assets/img/5-2.png',
                   ];
    for (let i = 0; i < preloads.length; i++) {
        images[i] = new Image()
        images[i].src = preloads[i]
    }
  }
}
